﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.Dim
{
    /// <summary>
    /// 获取维度信息
    /// </summary>
    [CPPEI.WebApi.AuthGetAction("Dim", "Get", "1.0")]
    public class GetAction : BaseAction<GetParams, GetResult>
    {
        protected override ActionResult<GetResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            GetParams opParams)
        {
            SER.DimService service = new SER.DimService();
            ServiceResult<ENT.EDim> serResult = service.GetDim(opParams.DimId);
            if(serResult.IsSuccess)
            {
                GetResult result = new GetResult();
                result.Id = serResult.Data.Id;
                result.Code = serResult.Data.Code;
                result.CreatedTime = serResult.Data.CreatedTime;
                result.Creator = serResult.Data.Creator;
                result.IsDeleted = serResult.Data.IsDeleted;
                result.IsEnabled = serResult.Data.IsEnabled;
                result.Name = serResult.Data.Name;
                return new ActionResult<GetResult>(result);
            }
            else
            {
                return new ActionResult<GetResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class GetParams
    {
        public Guid DimId { get; set; }
    }

    public class GetResult
    {
        public Guid Id { get; set; }

        public string Code { get; set; }

        public string Name { get; set; }

        public string Creator { get; set; }

        public DateTime CreatedTime { get; set; }

        public bool IsDeleted { get; set; }

        public bool IsEnabled { get; set; }
    }
}
